<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>{$web_name} - 编辑 - 域名</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__HOME__/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__HOME__/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">

            <div class="layui-card-body" pad15>
                <form id="systemForm" action="" method="post">
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">域名</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="id" id="id" class="layui-input" disabled>
                                <input type="text" name="domain" id="domain" class="layui-input" placeholder="不用写HTTP协议">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">生命周期/天</label>
                            <div class="layui-input-block">
                                <input type="text" name="cycle" id="cycle" lay-verify="text" class="layui-input" placeholder="留空或写入0表示不限制，则到期删除短网址">
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">过滤组</label>
                            <div class="layui-input-block">
                                <select name="filter_id"  id="filter_id">
                                    <option value="0">不过滤</option>

                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">防红守护</label>
                            <div class="layui-input-block">
                                <select name="safe"  id="safe" >
                                    <option value="1">守护</option>
                                    <option value="2">放任</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">防红模板</label>
                            <div class="layui-input-block">
                                <select name="safe_tpl"  id="safe_tpl" lay-filter="safe_tpl">
                                    <option value="" url="" selected>防红守护不开启则可以不选择</option>
                                    <option value="tpl1" url="__HOME__/static/index/tpl/tpl1.png">模板一</option>
                                    <option value="tpl2" url="__HOME__/static/index/tpl/tpl2.jpg">模板二</option>
                                    <option value="tpl3" url="__HOME__/static/index/tpl/tpl3.jpg">模板三</option>
                                    <option value="" url="">欢迎贡献其他模板</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <img id="product_img" src=""  style="display:inline-block;height:auto;max-width:15%;">
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <select name="state"  id="state" >
                                    <option value="" selected>请选择</option>
                                    <option value="1">正常生成</option>
                                    <option value="2">登录后生成</option>
                                    <option value="3">停止服务</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="addItem" >确认保存</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="__HOME__/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '__HOME__/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use([ 'index', 'form'],function() {
        var $ = layui.$
            ,form = layui.form;
        //Ajax设置
        $.ajaxSetup({
            type: 'POST',
            dataType : "json",
            headers: {'X-Requested-With': 'XMLHttpRequest'},
        });
        //-----------------处理结束--------------------//
        $.ajax({
            type: 'GET',
            url:  '{fun:ctr("../Domain/urlFilterList")}',
            success: function (res) {
                if (res.code == 200) {
                    $('#category option').empty();
                    var option = res.data;
                    var filter_select = '';
                    for (var o in option) {
                        filter_select += '<option value="' + option[o].id + '">' + option[o].filter_name + '</option>';
                    }
                    $('#filter_id').html(filter_select);
                    form.render('select');
                }
            }
        });
        form.on('submit(addItem)', function(data){
            //使用ajax发送请求
            $.ajax({
                url:  '{fun:ctr("../Domain/editDomainData")}',
                data:data.field,
                success:function(data){
                    if(data.code == 200){
                        layer.msg(data.msg, {icon: 1});
                        window.setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 500);
                    }else if(data.code == -7){
                        layer.msg(data.msg, {icon: 2});
                        window.setTimeout(function () {
                            top.location = '../Login';
                        }, 1000);
                    }else{
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error: function(data){
                    layer.msg('数据异常，操作失败！');
                },
            });
            return false;  //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        form.on('select(safe_tpl)', function(data){
            let url = $(data.elem).find("option:selected").attr("url")
            $('#product_img').attr('src', url);
        })
    });
</script>
</body>
</html>